package com.baor.service.impl;

import com.baor.dao.CommentDao;
import com.baor.service.CommentService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentDao commentDao;

    @Override
    public AjaxResult<?> insertComment(Map<String, Object> params) {
        if (this.commentDao.insertComment(params) > 0){
            return AjaxResult.success("评论成功");
        }else{
            return AjaxResult.error("评论失败");
        }
    }

    @Override
    public AjaxResult<?> selectComment(Map<String, Object> params) {
        params.put("pageIndex", (int)params.get("pageSize") * ((int)(params.get("pageIndex")) - 1));
        params.put("pageSize", params.get("pageSize"));
        Map<String,Object> res = new HashMap<>();
        res.put("commentList", commentDao.selectComment(params));
        res.put("pageCount", commentDao.pageCount(params));
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> deleteComment(Map<String, Object> params) {
        return AjaxResult.success(this.commentDao.deleteComment(params));
    }

    @Override
    public AjaxResult<?> updateCommentStatus(Map<String, Object> params) {
        return AjaxResult.success(this.commentDao.updateCommentStatus(params));
    }

    @Override
    public AjaxResult<?> selectCommentLevel() {
        return AjaxResult.success(this.commentDao.selectCommentLevel());
    }

    @Override
    public AjaxResult<?> replyComment(Map<String, Object> params) {
        return AjaxResult.success(this.commentDao.replyComment(params));
    }

    @Override
    public AjaxResult<?> selectGoods() {
        return AjaxResult.success(this.commentDao.selectGoods());
    }

    @Override
    public AjaxResult<?> updateCommentOrder(Map<String, Object> params) {
        return AjaxResult.success(this.commentDao.updateCommentOrder(params));
    }

    @Override
    public AjaxResult<?> cancelCommentOrder(Map<String, Object> params) {
        return AjaxResult.success(this.commentDao.cancelCommentOrder(params));
    }
}
